<template>
  <a-spin :spinning="confirmLoading">
    <!-- 主表单区域 -->
    <div style="width: 100%;text-align: center;font-size: 30px;font-weight: 600">《物资领用单》{{all}}</div>

    <a-form :form="form">
      <a-row>
        <a-col :xs="24" :sm="12" v-show="false">
          <a-form-item label="ID" :labelCol="labelCol" :wrapperCol="wrapperCol" >
            <a-input v-decorator="['id']"></a-input>
          </a-form-item>
        </a-col>

        <a-col :xs="24" :sm="12">
          <a-form-item label="领用部门" :labelCol="labelCol" :wrapperCol="wrapperCol">
            <j-select-depart    :disabled="true"  v-decorator="['newDepartment', validatorRules.newDepartment]"></j-select-depart>
          </a-form-item>
        </a-col>
        <!--          <a-col :xs="24" :sm="12">-->
        <!--            <a-form-item label="入库部门" :labelCol="labelCol" :wrapperCol="wrapperCol">-->
        <!--              <j-select-depart v-decorator="['oldDepartment', validatorRules.oldDepartment]"></j-select-depart>-->
        <!--            </a-form-item>-->
        <!--          </a-col>-->
        <a-col :xs="24" :sm="12">
          <!--          :disabled="disableSubmit"-->
          <a-form-item label="领用人" :labelCol="labelCol" :wrapperCol="wrapperCol">
            <j-search-select-tag    :disabled="true"    v-decorator="['recipientsUser', validatorRules.recipientsUser]"
                                    :trigger-change="true" dict="sys_user,realname,id"
                                    placeholder="请选择领用人"/>
          </a-form-item>
        </a-col>

        <!--        <a-col :xs="24" :sm="12" v-show="!disableSubmit">-->
        <!--          <a-form-item label="领用物资类型" :labelCol="labelCol"  >-->
        <!--            <a-radio-group  @change="getAssetList"  v-model:value="assetType" >-->
        <!--              <a-radio-button    value="YHP01">易耗品</a-radio-button>-->
        <!--              <a-radio-button    value="BGYP01">办公用品</a-radio-button>-->
        <!--              <a-radio-button   value="CHWZ01">存货物资</a-radio-button>-->
        <!--            </a-radio-group>-->
        <!--          </a-form-item>-->
        <!--        </a-col>-->

        <a-col :xs="24" :sm="12"   v-show="!disableSubmit">
          <a-form-item label="请选择领用物资" :labelCol="labelCol" :wrapperCol="wrapperCol">
            <j-select-fixds  :close="close"  :assetTypeF="assetType" :type="ty"  @change="handleView($event,props)"></j-select-fixds>
          </a-form-item>
        </a-col>
        <a-col :xs="24" :sm="12" v-show="!disableSubmit">

          <a-form-item label="物资导入" :labelCol="labelCol" :wrapperCol="wrapperCol">
            <a-upload :beforeUpload="beforeUpload" name="file" :showUploadList="false" :multiple="false"
                      :headers="tokenHeader"
                      @change="handleImportExcel"
                      :action="importExcelUrl"
            >



              <a-button type="primary" icon="import">导入</a-button>
            </a-upload>
            <a-button style="margin-left: 20px" type="primary" icon="download"
                      @click="handleExportXlsTemplate('领用导入模板')">
              模板下载
            </a-button>
          </a-form-item>
        </a-col>



        <a-col :xs="24" :sm="12">
          <a-form-item
            :labelCol="labelCol"
            :wrapperCol="wrapperCol"
            label="内控材料上传">
            <j-image-upload text="上传" v-decorator="['image', {}]" :isMultiple="true" :number="6"></j-image-upload>
          </a-form-item>
        </a-col>
      </a-row>
    </a-form>
    <!-- 子表单区域 -->
    <a-tabs v-model="activeKey" @change="handleChangeTabs">
      <a-tab-pane tab="物资领用记录表" :key="refKeys[0]" :forceRender="true">
        <j-editable-table
          @submit-add="appendToList"
          :ref="refKeys[0]"
          :loading="zcglRecipientsAssetsTable.loading"
          :columns="zcglRecipientsAssetsTable.columns"
          :dataSource="zcglRecipientsAssetsTable.dataSource"
          :maxHeight="300"

          :rowNumber="true"
          :disabled =disableSubmit
          :rowSelection="!disableSubmit"
          :actionButton="true">
          <template v-slot:assetId="props">
            <a-select
              v-if="props.text == assetValue"
              :default-value="props.text"
              placeholder="请选择物资名称"
              style="width: 100%;color: red"
              show-search
              disabled="true"
              optionFilterProp="label"
              @change="(value) => handleProChange(value, props.rowId)"
            >
              <a-select-option
                v-for="(item, i) in assetList"
                :key="i"
                :label="item.name"
                :value="item.id"
              >
                {{ item.name }}
              </a-select-option>
            </a-select>
            <a-select
              v-else
              :default-value="props.text"
              placeholder="请选择物资名称"
              style="width: 100%"
              show-search
              disabled="true"
              optionFilterProp="label"

              @change="(value) => handleProChange(value, props.rowId)"
            >
              <a-select-option
                :label="item.name"
                v-for="(item, i) in assetList"
                :key="i"
                :value="item.id"
              >
                {{ item.name }}
              </a-select-option>
            </a-select>
          </template>
          <template v-slot:assetCode="props">
            <a-input :value="props.text" disabled/>
          </template>
          <template v-slot:assetType="props">
            <a-input :value="props.text" disabled/>
          </template>
          <template v-slot:assetSpecifications="props">
            <a-input :value="props.text" disabled/>
          </template>
          <template v-slot:assetUnit="props">
            <a-input :value="props.text" disabled/>
          </template>
          <template v-slot:assetPrice="props">
            <a-input :value="props.text" disabled/>
          </template>
          <template v-slot:assetAmount="props">
            <a-input  :disabled="disableSubmit"   :value="props.text" @input="(e) => check(e.target.value, props.getValue(),props.rowId)"/>
          </template>
          <template v-slot:remark="props">
            <a-input  style="width: 260px"  :value="props.text" :disabled="disableSubmit" @input="(e) => check1(e.target.value, props.getValue(),props.rowId)"/>
          </template>
          <template v-slot:images="props">

            <img  height="25px" alt=""
                  @click="view(getImgView(props.text))"       :src="getImgView(props.text)"       style="max-width:80px;font-size: 12px;font-style: italic;"/>
          </template>
          <template v-slot:chwzType="props"
                    v-show="false"
          >
            <a-input    v-show="false" :value="props.text" :disabled="disableSubmit"/>
          </template>


        </j-editable-table>
      </a-tab-pane>
      <a-modal @cancel="picFlag=false" :visible="picFlag" width="1150px" height="670px"
               style="width: 1400px;height: 1100px">

        <div class="left" @mousewheel.prevent="rollImg" span="8">

          <img class="img" ref="imgDiv" @mousedown="move" id="img" :src="viewPic" height="600" alt=""
               style="max-width:1000px;font-size: 12px;font-style: italic;"/>
        </div>
        <template slot="footer">
          <a-button @click="picFlag=false">关闭</a-button>
        </template>
      </a-modal>
    </a-tabs>
  </a-spin>
</template>
<script>

import pick from 'lodash.pick'
import store from '@/store'
import { FormTypes, getRefPromise } from '@/utils/JEditableTableUtil'
import { JEditableTableMixin } from '@/mixins/JEditableTableMixin'
import JSelectDepart from '../../../components/jeecgbiz/JSelectDepart'
import JSelectAssets from '../../../components/jeecgbiz/JSelectAssets'
import JImageUpload from '../../../components/jeecg/JImageUpload'
import JSelectCangKu from '../../../components/jeecgbiz/JSelectCangKu'
import JSearchSelectTag from '../../../components/dict/JSearchSelectTag'
import { downFile, getAction, getFileAccessHttpUrl, postAction } from '../../../api/manage'
import JSelectFixds from '../../../components/jeecgbiz/JSelectFixds'
import AList from 'ant-design-vue/es/list'
import Vue from 'vue'
import { ACCESS_TOKEN } from '../../../store/mutation-types'
export default {
  name: 'ZcglRecipientsInfo',
  mixins: [JEditableTableMixin],
  components: {
    JSelectDepart, JSelectFixds, JImageUpload, JSelectCangKu, JSearchSelectTag
  },
  props: {
    assetValue: {
      type: Object,
      default: () => {
      }
    },
    allall: {
      type: Object,
      default: () => {
      }
    }
  },

  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
  },

  data () {
    return {
      tokenHeader: { 'X-Access-Token': Vue.ls.get(ACCESS_TOKEN) },
      allall:'',
      liuchengbianji:true,
      close:false,
      ty:2,
      picFlag:false,
      viewPic:"",
      assetType:"",
      // assetType:"",
      assetList: [],
      disableSubmit: false,
      labelCol: {
        xs: { span: 24 },
        sm: { span: 6 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      labelCol2: {
        xs: { span: 24 },
        sm: { span: 3 },
      },
      wrapperCol2: {
        xs: { span: 24 },
        sm: { span: 20 },
      },
      // 新增时子表默认添加几行空数据
      addDefaultRowNum: 1,
      validatorRules: {
        newDepartment: {
          rules: [
            { required: true, message: '请选择领用部门!' },
          ]
        },
        recipientsUser: {
          rules: [
            { required: true, message: '请选择领用人!' },
          ]
        }
      },
      refKeys: ['zcglRecipientsAssets',],
      tableKeys: ['zcglRecipientsAssets',],
      activeKey: 'zcglRecipientsAssets',
      // 物资领用记录表
      zcglRecipientsAssetsTable: {
        loading: false,
        dataSource: [],
        columns: [
          {
            title: '主键',
            key: 'id',
            type: FormTypes.hidden,
            width: '200px',

          },
          {
            title: '物资',
            key: 'assetId',
            type: FormTypes.select,
            dictCode: 'zcgl_asset_fixed,name,id',
            width: '450px',
            getData: true,
            disabled: true,
            allowSearch: true,
            defaultValue: '',
            validateRules: [{ required: true, message: '${title}不能为空' }]
          },
          // {
          //   title: '物资',
          //   key: 'assetId',
          //   type: FormTypes.slot,
          //   slotName: 'assetId',
          //   dictCode: 'zcgl_asset_fixed,name,id',
          //   width: '200px',
          //   getData: true,
          //   allowSearch: true,
          //   defaultValue: '',
          //   placeholder: '请选择${title}',
          //   validateRules: [{ required: true, message: '${title}不能为空' }]
          // },
          {
            title: '仓库',
            key: 'assetFixedCategoryId',
            type: FormTypes.select,
            disabled: true,
            // slotName: 'assetId',
            dictCode: 'zcgl_asset_fixed_category,name,id',
            width: '200px',
            getData: true,
            allowSearch: true,
            defaultValue: '',
            placeholder: '请选择${title}',
            validateRules: [{ required: true, message: '${title}不能为空' }]
          },



          {
            disabled: true,
            title: '物资编码',
            key: 'assetCode',
            slotName: 'assetCode',
            type: FormTypes.slot,
            width: '150px',
            placeholder: '请输入${title}',
            defaultValue: '',
          },
          {
            disabled: true,
            title: '物资分类',
            key: 'assetType',
            slotName: 'assetType',
            type: FormTypes.slot,
            width: '110px',
            placeholder: '请输入${title}',
            defaultValue: '',
          },
          {
            key: 'assetSpecifications',
            slotName: 'assetSpecifications',
            title: '规格型号',
            type: FormTypes.slot,
            width: '180px',
            disabled: true,
            placeholder: '请输入${title}',
            defaultValue: '',
          },
          {
            title: '单位',
            key: 'assetUnit',
            slotName: 'assetUnit',
            type: FormTypes.slot,
            width: '100px',
            disabled: true,
            placeholder: '请输入${title}',
            defaultValue: '',
          },
          {
            disabled: true,
            title: '目前可用数量',
            key: 'trueCount',
            type: FormTypes.inputNumber,
            width: '110px',
            defaultValue: ''
          },
          {
            disabled: true,
            title: '流程占用数量',
            key: 'lcCount',
            type: FormTypes.inputNumber,
            width: '110px',
            defaultValue: ''
          },
          {
            title: '本次领用数量',
            key: 'assetAmount',
            width: '110px',
            slotName: 'assetAmount',
            type: FormTypes.slot,
            jisuan: true,
            jisuanSl: true,
            placeholder: '请输入${title}',
            defaultValue: '',
            validateRules: [{ required: true, message: '${title}不能为空' }]
          },
          {
            title: '备注说明',
            key: 'remark',
            type: FormTypes.slot,
            width: '260px',
            placeholder: '请输入${title}',
            defaultValue: '',
            slotName: 'remark',
          },
          {
            title: '图片',
            key: 'image',
            slotName: 'images',
            type: FormTypes.slot,
            width: '110px',
            defaultValue: '',
          },
          {
            title: '小分类',
            key: 'chwzType',
            slotName: 'chwzType',
            type: "hidden",
            // type: FormTypes.slot,
            width: '110px',
            defaultValue: '',
            hidden:true
          },
          // {
          //   disabled: true,
          //   title: '物资合计',
          //   key: 'total',
          //   type: FormTypes.normal,
          //   width:"200px",
          //   placeholder: '请输入${title}',
          //   defaultValue: '',
          // },

        ]
      },
      url: {
        importExcelUrl: 'zcgl/assetFixed/importExcelAssetLY',
        add: '/zcglRecipients/zcglRecipients/add',
        adda: '/zcglRecipients/zcglRecipients/adda',
        edit: '/zcglRecipients/zcglRecipients/edit',
        zcglRecipientsAssets: {
          list: '/zcglRecipients/zcglRecipients/queryZcglRecipientsAssetsByMainId'
        },
      }
    }
  },
  created () {
    // this.getAssetList()
    // this.assetType = 'CHWZ01'

  },
  methods: {

    beforeUpload (file) {

      return new Promise((resolve, reject) => {
        this.$confirm({
          content: '确定导入吗？',
          onOk: () => {
            console.log('ok ')
            resolve(file)
          },
          onCancel: () => {
            console.log('cancel')
            reject(file)
          },
        })
      })
    },
    /* 导入 */
    handleImportExcel (info) {
      // if(this.assetList.length == 0){
      //   this.getAssetList()
      // }


      if (info.file.status !== 'uploading') {
        console.log(info.file, info.fileList)
      }
      if (info.file.status === 'done') {
        if (info.file.response.success) {
          // this.$message.success(`${info.file.name} 文件上传成功`);
          if (info.file.response.code === 201) {
            let { message, result: { msg, fileUrl, fileName } } = info.file.response
            let href = window._CONFIG['domianURL'] + fileUrl
            this.$warning({
              title: message,
              content: (
                <div>
                  <span>{msg}</span>
                  <br/>
                  <span>具体详情请
                    <a href={href} target="_blank" download={fileName}>点击下载</a>
                  </span>
                </div>
              )
            })

            // `<div>
            //   <span>${msg}</span><br/>
            //   <span>具体详情请 <a href=${href} target="_blank" download=${fileName}>点击下载</a> </span>
            // </div>`
          } else {



            for (let i = 0; i < info.file.response.result.length; i++) {
              var item = info.file.response.result[i]
              var type = ''
              type = item.assetType
              if (item.assetType == 'YHP01') {
                type = '易耗品'
              }
              if (item.assetType == 'BGYP01') {
                type = '办公用品'
              }
              if (item.assetType == 'CHWZ01') {
                type = '存货物资'
              }
              if (item.assetType == 'BGYP') {
                type = '办公用品'
              }
              if (item.assetType == '2') {
                type = '医用耗材'
              }
              if (item.assetType == '1') {
                type = '检验试剂'
              }

              // if(item.assetType != this.assetTypeF){
              //
              //   alert("物资类型和当前领用单类型不匹配，请重新选择！")
              //   return
              // }
              if(typeof  this.zcglRecipientsAssetsTable.dataSource ==  "undefined"){
                this.zcglRecipientsAssetsTable.dataSource = []
              }
              if (JSON.stringify(this.zcglRecipientsAssetsTable.dataSource).indexOf(item.id) == -1) {
                //存在就不做处理吧
                this.zcglRecipientsAssetsTable.dataSource.push({
                  assetId: item.id,
                  assetUnit: item.unit,
                  assetName: item.name,
                  assetPrice: item.price,
                  assetCode: item.code,
                  assetSpecifications: item.specifications,
                  assetType: type,
                  image: item.image,
                  trueCount: item.trueCount,
                  lcCount: item.lcCount,
                  money: item.money,
                  assetAmount: item.amount,
                  assetFixedCategoryId: item.assetFixedCategoryId,
                })
              }else{
                alert("重复数据导入失败，请仔细检查物资，导入失败的数据为："+item.name)


              }
            }
            this.$warning({
              title: '导入结果',
              content: (
                info.file.response.message || `${info.file.name} 文件上传成功`
              ),
              onOk: () => {
                this.aavisible = false
              },
            })

          }
          // this.loadData()
        } else {

          this.$warning({
            title: '导入结果',
            content: (
              `${info.file.name} ${info.file.response.message}.`
            ),
            onOk: () => {
              this.aavisible = false
            },
          })

        }
      } else if (info.file.status === 'error') {
        alert(`文件上传失败: ${info.file.msg} `)
      }
    },

    handleExportXlsTemplate (fileName) {
      if (!fileName || typeof fileName != 'string') {
        fileName = '模板'
      }
      console.log('下载模板：' + fileName)
      downFile('zcgl/assetFixed/downloadUserTemplateAssetLingYong', { title: fileName }).then((data) => {
        if (!data) {
          this.$message.warning('模板下载失败')
          return
        }
        if (typeof window.navigator.msSaveBlob !== 'undefined') {
          window.navigator.msSaveBlob(new Blob([data], { type: 'application/vnd.ms-excel' }), fileName + '.xls')
        } else {
          let url = window.URL.createObjectURL(new Blob([data], { type: 'application/vnd.ms-excel' }))
          let link = document.createElement('a')
          link.style.display = 'none'
          link.href = url
          link.setAttribute('download', fileName + '.xls')
          document.body.appendChild(link)
          link.click()
          document.body.removeChild(link) //下载完成移除元素
          window.URL.revokeObjectURL(url) //释放掉blob对象
        }
      })
    },

    appendToList: function(item) {
      // alert(JSON.stringify(item))
      this.zcglRecipientsAssetsTable.dataSource = item
    },
    // 拖动图片
    move(e) {
      e.preventDefault();
      // 获取元素
      var left = document.querySelector(".left");
      var img = document.querySelector(".img");
      var x = e.pageX - img.offsetLeft;
      var y = e.pageY - img.offsetTop;
      // 添加鼠标移动事件
      left.addEventListener("mousemove", move);

      function move(e) {
        img.style.left = e.pageX - x + "px";
        img.style.top = e.pageY - y + "px";
      }

      // 添加鼠标抬起事件，鼠标抬起，将事件移除
      img.addEventListener("mouseup", function () {
        left.removeEventListener("mousemove", move);
      });
      // 鼠标离开父级元素，把事件移除
      left.addEventListener("mouseout", function () {
        left.removeEventListener("mousemove", move);
      });
    },
    // 缩放图片
    rollImg() {
      /* 获取当前页面的缩放比 若未设置zoom缩放比，则为默认100%，即1，原图大小 */

      var zoom = parseInt(this.$refs.imgDiv.style.zoom) || 100;
      /* event.wheelDelta 获取滚轮滚动值并将滚动值叠加给缩放比zoom wheelDelta统一为±120，其中正数表示为向上滚动，负数表示向下滚动 */

      zoom += event.wheelDelta / 12;
      /* 最小范围 和 最大范围 的图片缩放尺度 */

      if (zoom >= 80 && zoom < 500) {
        this.$refs.imgDiv.style.zoom = zoom + "%";
      }
      return false;
    },
    view(text) {
      this.picFlag = true
      this.viewPic = text
    },
    /* 图片预览 */
    getImgView(text){
      if(text && text.indexOf(",")>0){
        text = text.substring(0,text.indexOf(","))
      }
      return getFileAccessHttpUrl(text)
    },
    /** 调用完edit()方法之后会自动调用此方法 */
    getAssetList () {

      // setTimeout(() => {
      //
      //
      //   //清空
      //   this.zcglRecipientsAssetsTable.dataSource = []
      //   //这里我先改成1
      //   getAction('/zcgl/assetFixed/allallList?all='+this.allall, {type:"1", 'assetType': this.assetType,"pageNo":1,"pageSize":4000}).then((res) => {
      //     if (res.success) {
      //       alert(JSON.stringify(res.result.records))
      //       this.assetList = res.result.records
      //
      //     }
      //   })
      // }, 3000);

    },
    check1 (target, data,id) {

      let values = [
        {
          rowKey: id,
          values: {
            'remark': target
          },
        },
      ]
      this.$refs.zcglRecipientsAssets.setValues(values)
    },
    check (target, data,id) {
      let item = this.assetList.find((ele) => ele.id == data.assetId)
      if (item.trueCount < target) {
        this.$error({ title: '数据错误！', content: '错误信息：不能大于可领用数量(可领用数量=库存数量-目前已进入审批流程的占用数量)' })
        let values = [
          {
            rowKey: id,
            values: {
              'assetAmount': ''
            },
          },
        ]
        this.$refs.zcglRecipientsAssets.setValues(values)
      }else{
        let values = [
          {
            rowKey: id,
            values: {
              'assetAmount': target
            },
          },
        ]
        this.$refs.zcglRecipientsAssets.setValues(values)
      }
    },
    handleProChange (value, id) {
      let item = this.assetList.find((ele) => ele.id == value)

      let values = [
        {
          rowKey: id,
          values: {
            'assetId': item.id,
            'assetCode': item.code,
            'assetType': item.assetType,
            'chwzType': item.chwzType,
            'trueCount': item.trueCount,
            'assetSpecifications': item.specifications,
            'assetUnit': item.unit,
            'image': item.image,
          },
        },
      ]
      this.$refs.zcglRecipientsAssets.setValues(values)
    },
    handleView (a, b) {
      getAction('/zcgl/assetFixed/getMulFixed', { id: a }).then((res) => {
        if (res.success) {
          for (let i = 0; i < res.result.length; i++) {
            var item = res.result[i]
            var type = item.assetType

            if (item.assetType == 'YHP01') {
              type = '易耗品'
            }
            if (item.assetType == 'BGYP01') {

              type = '办公用品'
            }
            if (item.assetType == 'CHWZ01') {
              type = '存货物资'
            }
            if (item.assetType == 'BGYP') {
              type = '办公用品'
            }
            if (item.assetType == '2') {
              type = '医用耗材'
            }
            if (item.assetType == '1') {
              type = '检验试剂'
            }

            if(typeof  this.zcglRecipientsAssetsTable.dataSource ==  "undefined"){
              this.zcglRecipientsAssetsTable.dataSource = []
            }
            if (JSON.stringify(this.zcglRecipientsAssetsTable.dataSource).indexOf(item.id) == -1) {
              //存在就不做处理吧

              this.zcglRecipientsAssetsTable.dataSource.push({
                assetId: item.id,
                assetUnit: item.unit,
                assetName: item.name,
                assetCode: item.code,
                assetPrice: item.price,
                trueCount: item.trueCount,
                lcCount: item.lcCount,
                assetSpecifications: item.specifications,
                assetType: type,
                chwzType: item.chwzType,
                assetFixedCategoryId: item.assetFixedCategoryId,

                image:item.image
              })
            }
          }
        }
      })
      // this.zcglPutStorageAssetsTable.dataSource[b.index].assetId = a
    },
    getAllTable () {
      let values = this.tableKeys.map(key => getRefPromise(this, key))
      return Promise.all(values)
    },
    /** 调用完edit()方法之后会自动调用此方法 */
    showModal (r) {

      setTimeout(() => {

        let usercode = store.getters.userInfo.id
        //根据code去获取小部门的ID
        let currentCompanyId = store.getters.userInfo.orgCode
        // this.getAssetList()
        getAction('/sys/sysDepart/getDepartByCode', {orgCode:currentCompanyId}).then((res) => {
          if (res.success) {
            currentCompanyId = res.result.id
            this.model = Object.assign({}, r)
            if(this.liuchengbianji == true){
              this.$message.info("重新校验可领用数量中")
              let param = {};
              param.data = this.model.zcglRecipientsAssetsList

              postAction('/zcgl/assetFixed/getNewCount', param).then((res) => {

                this.zcglRecipientsAssetsTable.dataSource = res.result
                this.$message.success("刷新领用数据成功")
                return
              })
            }
            if(this.model.orderNo && this.model.id != '1590665592578457602'){
              //获取所有的物资选项
              this.assetType = ""


              let fieldval = pick(this.model, 'id','newDepartment', 'oldDepartment', 'recipientsUser', 'processStatus', 'processStatusText', 'processDescription', 'trueCount')
              this.$nextTick(() => {
                this.form.setFieldsValue(fieldval)
              })
            }else{
              //自动赋值  当前登陆人   和当前部门
              this.model.recipientsUser = usercode
              this.model.newDepartment = currentCompanyId
              let fieldval = pick(this.model, 'id','newDepartment', 'oldDepartment', 'recipientsUser', 'processStatus', 'processStatusText', 'processDescription', 'trueCount')
              this.$nextTick(() => {
                this.form.setFieldsValue(fieldval)
              })
            }
            setTimeout(() => {


              //清空
              // this.zcglRecipientsAssetsTable.dataSource = []
              //这里我先改成1
              getAction('/zcgl/assetFixed/allallList?all='+this.allall, {type:"1", 'assetType': this.assetType,"pageNo":1,"pageSize":4000}).then((res) => {
                if (res.success) {
                  this.assetList = res.result.records

                }
              })
            }, 1);

            // 加载子表数据

            this.zcglRecipientsAssetsTable.dataSource = this.model.zcglRecipientsAssetsList




          }
        })


      },100)


    },
    /** 调用完edit()方法之后会自动调用此方法 */
    editAfter () {

      setTimeout(() => {

        let fieldval = pick(this.model, 'newDepartment', 'oldDepartment', 'recipientsUser', 'processStatus', 'processStatusText', 'processDescription')

        this.$nextTick(() => {
          this.form.setFieldsValue(fieldval)
        })
        // 加载子表数据
        if (this.model.id) {
          let params = { id: this.model.id }
          this.requestSubTableData(this.url.zcglRecipientsAssets.list, params, this.zcglRecipientsAssetsTable)

        }
      },1000)


    },
    /** 整理成formData */
    classifyIntoFormData (allValues) {
      let main = Object.assign(this.model, allValues.formValue)
      return {
        ...main, // 展开
        zcglRecipientsAssetsList: allValues.tablesValue[0].values,
      }
    },
    validateError (msg) {
      this.$message.error(msg)
    },
    popupCallback (row) {
      this.form.setFieldsValue(pick(row, 'newDepartment', 'oldDepartment', 'recipientsUser', 'processStatus', 'processStatusText', 'processDescription'))
    },

  }
}
</script>

<style scoped>
</style>